#include <iostream>
using namespace std;

//食物
class abstractFood
{
public:
	virtual void show() = 0;
};
class Apple :public abstractFood
{
public:
	void show()
	{
		cout << "Apple" << endl;
	}
};
class Orange :public abstractFood
{
public:
	void show()
	{
		cout << "Orange" << endl;
	}
};
class Pork :public abstractFood
{
public:
	void show()
	{
		cout << "Pork" << endl;
	}
};
class Beef :public abstractFood
{
public:
	void show()
	{
		cout << "Beef" << endl;
	}
};
//工厂

class foodFactory
{
public:
	virtual abstractFood* getFood(string food) = 0;
};
class fruitFactory :public foodFactory
{
public:
	abstractFood* getFood(string fruit)
	{
		if (fruit=="Apple")
			return new Apple();
		else if (fruit == "Orange")
			return new Orange();
		else
			return nullptr;
	}
};
class MeatFactory :public foodFactory
{
public:
	abstractFood* getFood(string meat)
	{
		if (meat == "Pork")
			return new Pork();
		else if (meat == "Beef")
			return new Beef();
		else
			return nullptr;
	}
};

int main()
{
	foodFactory* foodFac;
	foodFac = new fruitFactory();

	abstractFood* food;
	food = foodFac->getFood("Apple");
	food->show();
	food = foodFac->getFood("Orange");
	food->show();

	foodFac = new MeatFactory();
	food = foodFac->getFood("Pork");
	food->show();
	food = foodFac->getFood("Beef");
	food->show();
}

